package _06xpath全文搜索;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import java.util.List;

public class Demo6 {
    public static void main(String[] args) throws DocumentException {
        SAXReader reader = new SAXReader();
        Document document = reader.read("Day_14\\xpath_contact.xml");
        //全文检索name标签，不管调用者是谁都会全篇去查询
        Element rool = document.getRootElement();
        List<Node> nodes = rool.selectNodes("//name");
        for (Node node : nodes) {
            System.out.println(node.getText());
        }
        //所有contact下的子标签中的name
        System.out.println("---------------");
        List<Node> nodes1 = rool.selectNodes("//contact/name");
        for (Node node : nodes1) {

            System.out.println(node.getText());
        }
        System.out.println("---------------");

        //所有contact下的所有name
        List<Node> nodes2 = rool.selectNodes("//contact//name");
        for (Node node : nodes2) {

            System.out.println(node.getText());
        }
    }
}
